def extract_admission_diagnosis(lines):
    """
    从文本行列表中提取入院诊断部分，包括从'入院诊断'行到'诊断时间'行之间的所有内容

    参数:
    lines -- 包含文本行的列表

    返回:
    包含入院诊断部分的列表
    """
    diagnosis_section = []
    start_index = -1
    end_index = -1

    # 查找"入院诊断"和"诊断时间"的行索引
    for i, line in enumerate(lines):
        if isinstance(line, str):
            line_content = line.strip()
            if '入院诊断' in line_content and start_index == -1:
                start_index = i
            elif '诊断时间' in line_content and start_index != -1 and end_index == -1:
                end_index = i
                break

    # 如果找到了开始和结束位置，提取相应的行
    if start_index != -1 and end_index != -1:
        diagnosis_section = lines[start_index:end_index+1]

    return diagnosis_section

def convert_to_diagnosis_dict(lines):
    """
    将入院诊断相关的文本行转换为包含诊断内容和时间的字典
    """
    result = {
        "入院诊断": [],
        "诊断时间": ""
    }

    for line in lines:
        stripped = line.strip()
        if not stripped:
            continue  # 跳过空行

        # 跳过标题行
        if stripped == "入院诊断":
            continue

        # 提取诊断时间
        if stripped.startswith("诊断时间"):
            # 支持中文冒号或英文冒号
            separator = "：" if "：" in stripped else ":" if ":" in stripped else None
            if separator:
                result["诊断时间"] = stripped.split(separator, 1)[1].strip()
            else:
                result["诊断时间"] = stripped[4:].strip()  # 默认去掉前4个字
            continue

        # 其余非空行视为诊断内容（不再限制编号）
        result["入院诊断"].append(stripped)

    return result